<!DOCTYPE html>
<html>
<head>
    <div th:include="base-libs :: base-libs" />
    <title>床位预约-新增/修改</title>

    <meta name="keywords" content="keyword1,keyword2,keyword3">
    <meta name="description" content="this is my page">
    <meta name="content-type" content="text/html; charset=UTF-8">

    <style>
        .hidden{
            display:none;
        }
        .combo{
            width:208px !important;
        }
    </style>

    <script th:inline="javascript">
        var requestData = [[${requestData}]];
    </script>
    <script>
        $(function(){
            $(this).registerManagerPage();
            initView();
            initData();
        })

        function initView(){
            //保存
            $("#btnBc").click(function(){
                if($(".form-control").QuickValidate()){
                    var YJKSMC = $("#YJKSDM option:selected").text();
                    var BQMC   = $("#BQDM option:selected").text();
                    var CWSYL = $("#CWSYL").val().split("%");

                    var params = {
                        YJKSMC: YJKSMC,
                        BQMC: BQMC,
                        CWSYL: CWSYL[0]
                    }
                    $.QuickRemote.AjaxFiledFormSubmit("cwyyglForm", saveHandler, params);
                }
            })

            //返回
            $("#btnFh").click(function(){
                $.QuickUrlUtils.redirectUrl("index.html");
            })
            //床位使用率计算
            $("#SJKFCWS,#DQKCS").keyup(function(){
                var SJKFCWS = parseInt($("#SJKFCWS").val());
                var DQKCS = parseInt($("#DQKCS").val());
                var result;
                if(SJKFCWS && DQKCS){
                    result = ((SJKFCWS-DQKCS)/SJKFCWS*100).toFixed(0) + '%';
                }
                $("#CWSYL").val(result);
            })
            //查询科室病区
            $("#YJKSDM").change(function(){
                var YLJGDM = $("#YLJGDM").val();
                var YJKSDM = $("#YJKSDM").val();
                initBqxx({YLJGDM:YLJGDM,YJKSDM:YJKSDM});
            })


            /** 医疗机构combogrid */
            var readonly = !requestData["isManager"];
            $("#combogridYljg").combogrid({
                height: 30
                ,width: 300
                ,panelWidth: 500
                ,singleSelect: true
                ,pagination: true
                ,idField: 'YLJGDM'
                ,textField: 'YLJGMC'
                ,mode: "remote"
                ,readonly: readonly
                ,hasDownArrow: !readonly
                ,url: "/console/yljgxx/queryPageSummary.service"
                ,delay: 1000
                ,reversed: false
                ,columns:[[
                    {field:'YLJGMC',title:'机构名称',width:240},
                    {field:'XZQHMC',title:'行政区划',width:80},
                    {field:'WSJGLBMC',title:'机构类别',width:80},
                    {field:'YYDJMC',title:'机构等级',width:80}
                ]]
                ,onBeforeLoad: function(queryParams) {
                    var url = $(this).datagrid("options")["url"];
                    /*URL不等空时再发送请求*/
                    if (!readonly) {
                        queryParams["pageSize"] = queryParams["rows"];
                        queryParams["pageNumber"] = queryParams["page"];
                        queryParams["YLJGMC"] = queryParams["q"];
                        var result = [];
                        $("#YJKSDM").createOptions(result,{textField : "KSMC" , valueField : "KSDM"});
                        return true;
                    }else{
                        return false;
                    }
                },
                onClickRow : function(rowIndex, rowData){
//                    alert(JSON.stringify(rowData));
                    initKsxx(rowData);
                },
                onLoadSuccess : function(data){

                }
            });

        }

        function initData(){
            var cwyyglData = StoreCache.removeCache('cwyyglData');
            if(!$.isEmptyObject(cwyyglData)){
                $("#combogridYljg").combogrid("setValue", cwyyglData);
                initKsxx(cwyyglData);

                $("#type").val('update');
                $(".form-control").each(function(){
                     name = $(this).attr('name');
                    $(this).val(cwyyglData[name]);
                })
                $("#CWSYL").val(cwyyglData.CWSYL);
            }else if(!requestData["isManager"]){
                $.QuickRemote.AjaxJson("/console/yljgxx/queryPageSummary.service", function (result) {
                    var yljgxx = result.rows[0];
                    $("#combogridYljg").combogrid("setValue", yljgxx);
                    initKsxx(yljgxx);
                }, {PTJGID: parent.userInfo.PTJGID,pageSize:1,pageNumber:1});

             }
            $("#SJKFCWS").trigger("keyup");
        }

        /** 保存回调 */
        function saveHandler(result){
            if(result.state){
                $.QuickAlert.alertNormal(result.info, {callback: function(){
                    $("#btnFh").trigger("click");
                }});
            }else{
                $.QuickAlert.alertFail({content: result.info});
            }
        }

        /** 初始化一级科室下拉框 */
        function initKsxx(params2){
            var params = $.extend({},params2);//处理乱码
            $("#YLJGDM").val(params.YLJGDM);
            $("#YLJGMC").val(params.YLJGMC);
            $("#XZQHMC").val(params.XZQHMC);
            $("#XZQHDM").val(params.XZQHDM);
            $("#YYDJDM").val(params.YYDJDM);
            $("#YYDJMC").val(params.YYDJMC);

            $.QuickRemote.AjaxJson( "queryYjksByPtjgid", function(result){
                $("#YJKSDM").createOptions(result,{textField : "KSMC" , valueField : "KSDM"});
                $("#YJKSDM").val(params.YJKSDM);
                initBqxx(params);
            }, {YLJGDM: params.YLJGDM});
        }

        /** 初始化病区下拉框 */
        function initBqxx(params){
            $.QuickRemote.AjaxJson("queryBqxxByPtjgid", function(result){
                $("#BQDM").createOptions(result,{textField : "BQMC" , valueField : "BQDM"});
                $("#BQDM").val(params.BQDM);
            }, {YLJGDM: params.YLJGDM, KSDM: params.YJKSDM});
        }

    </script>
</head>

<body class="easyui-layout">
<div region="center">
    <h4 class="h4-title" style="text-align:center;margin:0;padding:0;font-size: 16px;height: 30px;line-height: 30px;">
        床位预约管理
    </h4>
    <input id="PTJGID" type="hidden" hidden />
    <form action="save" id="cwyyglForm">
        <input id="type" name="type" class="hidden" value="add"/>
        <input name="CWXXBH" class="form-control hidden"/>
        <table class="form-table">
            <tr>
                <td class="td-text" style="width:12%"><label>医疗机构名称</label></td>
                <td class="td-content" style="">
                    <input id="combogridYljg" />

                    <input id="YLJGMC" name="YLJGMC" class="form-control hidden"
                           quick-config="label:'医疗机构名称', validateProxy:'notNull'"/>
                    <input id="YLJGDM" name="YLJGDM" class="form-control hidden"/>
                    <input id="YYDJDM" name="YYDJDM" class="form-control hidden"/>
                    <input id="YYDJMC" name="YYDJMC" class="form-control hidden"/>
                    <input id="XZQHDM" name="XZQHDM" class="form-control hidden"/>
                    <input id="XZQHMC" name="XZQHMC" class="form-control hidden"/>

                </td>
                <td class="td-text" style="width:12%"><label>科室名称</label></td>
                <td class="td-content">
                    <select id="YJKSDM" name="YJKSDM" class="form-control" quick-config="label:'科室名称', validateProxy:'notNull'">
                        <option value="">请选择</option>
                    </select>
                </td>
                <td class="td-text" style="width:12%"><label>病区名称</label></td>
                <td class="td-content">
                    <select id="BQDM" name="BQDM" class="form-control" quick-config="label:'病区名称', validateProxy:'notNull'">
                        <option value="">请选择</option>
                    </select>
                </td>
            </tr>
            <tr>
                <td class="td-text"><label>实际开放床位数</label></td>
                <td class="td-content">
                    <input id="SJKFCWS" name="SJKFCWS" class="form-control"
                           quick-config="label:'实际开放床位数', validateProxy:'notNull length num', length:'8'"/>
                </td>
                <td class="td-text"><label>当前空床数</label></td>
                <td class="td-content">
                    <input id="DQKCS" name="DQKCS" class="form-control"
                           quick-config="label:'当前空床数', validateProxy:'notNull length num', length:'8'"/>
                </td>
                <td class="td-text"><label>已预约床位数</label></td>
                <td class="td-content">
                    <input  name="YYYCWS" class="form-control"
                           quick-config="label:'已预约床位数', validateProxy:'notNull length num', length:'8'"/>
                </td>
            </tr>
            <tr>
                <td class="td-text"><label>当前可预约床位数</label></td>
                <td class="td-content">
                    <input name="DQKYYCWS" class="form-control"
                           quick-config="label:'当前可预约床位数', validateProxy:'notNull length num', length:'8'"/>
                </td>
                <td class="td-text"><label>3天内预计空床数</label></td>
                <td class="td-content" >
                    <input name="STNYJKCS" class="form-control"
                           quick-config="label:'3天内预计空床数', validateProxy:'notNull length num', length:'8'"/>
                </td>
                <td class="td-text" ><label>3天内可预约床位数</label></td>
                <td class="td-content">
                    <input name="STNKYYCWS" class="form-control"
                           quick-config="label:'3天内可预约床位数', validateProxy:'notNull length num', length:'8'"/>
                </td>
            </tr>
            <tr>
                <td class="td-text"><label>1周内预计空床数</label></td>
                <td class="td-content">
                    <input name="YZNYJKCS" class="form-control"
                           quick-config="label:'1周内预计空床数', validateProxy:'notNull length num', length:'8'"/>
                </td>
                <td class="td-text"><label>1周内可预约床位数</label></td>
                <td class="td-content">
                    <input name="YZNKYYCWS" class="form-control"
                           quick-config="label:'1周内可预约床位数', validateProxy:'notNull length num', length:'8'"/>
                </td>
                <td class="td-text"><label>等待床位数</label></td>
                <td class="td-content">
                    <input name="DDCWS" class="form-control"
                           quick-config="label:'等待床位数', validateProxy:'length num', length:'8'"/>
                </td>
            </tr>
            <tr>
                <td class="td-text"><label>床位使用率</label></td>
                <td class="td-content" >
                    <input id="CWSYL" class="form-control " readonly="readonly" />
                </td>
            </tr>
        </table>


    </form>

</div>

<div region="south" style="height:50px;line-height:50px;text-align:center;overflow:hidden;border:0;border-top:1px solid #ddd">
    <button id="btnBc" class="btn btn-info" type="button">保存</button>
    <button id="btnFh" class="btn btn-info" type="button">返回</button>
</div>

</body>


</html>
